package com.exam;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

public class SearchFile {
    public static void main(String[] args) throws IOException {
        File root = new File("D:/");
        File[] files = root.listFiles();
        if (files != null) {
            for (File f : files) {
                if(searchFile(f)){
                    break;
                }
            }
        }

    }
    public static boolean searchFile(File file) throws IOException {
        if (file == null || !file.exists()) return false;
        File[] files = file.listFiles();
        if (files == null) return false;
        for(int i = 0;i < files.length;i++){
            if(files[i].isFile() && files[i].getName().equals("7z.exe")){
                System.out.println(files[i].getAbsolutePath());
                return true;
            }
            else if (files[i].isDirectory()){
                if(searchFile(files[i])){
                    return  true;
                }

            }
        }
        return false;
    }
}
